#!/bin/sh
#
# Perform necessary inspec removal steps
# after package is uninstalled.
#

is_darwin()
{
  uname -a | grep "^Darwin" 2>&1 >/dev/null
}

if is_darwin; then
    PREFIX="/usr/local"
else
    PREFIX="/usr"
fi

cleanup_symlinks() {
  binaries="inspec"
  for binary in $binaries; do
    rm -f $PREFIX/bin/$binary
  done
}

# Clean up binary symlinks if they exist
# see: http://tickets.opscode.com/browse/CHEF-3022
if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release ]; then
  # not a redhat-ish RPM-based system
  cleanup_symlinks
elif [ "x$1" = "x0" ]; then
  # RPM-based system and we're deinstalling rather than upgrading
  cleanup_symlinks
fi

echo "Chef InSpec has been uninstalled!"

exit 0
